// import { createApp } from "vue";
// const app = createApp({});

// 注册对应包下的所有组件
function register(context) {
  let list = [];
  context.keys().forEach((item) => {
    const component = context(item);
    let ctrl = component.default || component;
    let name = ctrl.name;
    list.push({ name: name, component: ctrl });
  });
  return list;
}

// 获取所有属性配置组件 initializing
function registerSchemaInitializing() {
  const files = require.context(
    "@/components/custom-schema-template",
    true,
    /initializing.js$/
  );
  const list = [];
  files.keys().forEach((key) => {
    let name = key.replace(/(\.\/|\/initializing.js)/g, "");
    let [, componentName] = name.split("/");
    list.push({ component: componentName, ...files(key).default });
  });
  return list;
}

// register(
//   require.context(
//     "@/components/custom-schema-template-set/config-template",
//     true,
//     /.vue/
//   )
// );

export default {
  $cmpConfig: registerSchemaInitializing(),
  $register: register(
    require.context(
      "@/components/custom-schema-template-set/config-template",
      true,
      /.vue/
    )
  ),
  $registerGlobal: register(
    require.context("@/components/global", true, /.vue/)
  ),
  $registerComponent: register(
    require.context("@/components/custom-schema-template", true, /.vue/)
  )
};
